package com.ruoyi.web.controller.service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.web.controller.domain.ShortLink;
import com.ruoyi.web.controller.mapper.ShortLinkIndexMapper;
import com.ruoyi.web.controller.mapper.ShortLinkMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class ShortLinkServiceImpl extends ServiceImpl<ShortLinkMapper, ShortLink> implements IShortLinkService {

    @Resource
    private ShortLinkIndexMapper shortLinkIndexMapper;
    @Resource
    private ShortLinkMapper shortLinkMapper;

    public static final int END_INDEX = 900;

    @Override
    public List<String> getList() {
        Long index = shortLinkIndexMapper.selectIndex();
        // 通过index 开始查，查询出900条，然后更新ShortLinkIndex
        List<String> list = shortLinkMapper.selectListKey(index.intValue(), END_INDEX);
        shortLinkIndexMapper.updateIndex(index + END_INDEX + 1,index);
        return list;
    }
}
